package cn.buddha.jec.util;

import cn.buddha.jec.exception.enums.TongExceptionEnum;

import java.util.Scanner;

/**
 * @ClassName TongUtils
 * @Author 友野浩二
 * @Description 公共处理类
 * @Version 1.0
 */
public class TongUtils {

    /**
     * @Author 友野浩二
     * @Description // 读取控制台内容
     * @Date 2019/11/3 1:53
     * @Param [tip]
     * @return java.lang.String
     */
    public static String scanner(final String tip) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder help = new StringBuilder();

        help.append("请输入").append(tip).append(": ");
        System.err.println(help);

        if (scanner.hasNext()) {
            String ipt = scanner.next();
            if (!TongStringUtils.isEmpty(ipt)) {
                return ipt;
            }
        }

        throw TongBusinessUtils.createBusinessException(TongExceptionEnum.MYBATIS_GENERATOR_FAIL.getCode(),
                String.format(TongExceptionEnum.MYBATIS_GENERATOR_FAIL.getMessage(), tip));
    }

    /**
     * @return java.lang.String
     * @Author 友野浩二
     * @Description // 将类名首字母小写(变驼峰)
     * @Date 2020/4/3 0:06
     * @Param [str]
     */
    public static String lowerFistChar(String str) {
        char[] chars = str.toCharArray();
        chars[0] += 32;
        return String.valueOf(chars);
    }

}
